/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/08/10
*/
#include "WindowMgr.h"
#include "../interface/IWindow.h"

EDUI_NAMESPACE_BEGIN

WindowMgr::WindowMgr()
{}

WindowMgr::~WindowMgr()
{}

void WindowMgr::RemoveByID(Uint32 wndID)
{
    if (wndID < 0) return;
    for (size_t i = 0; i < this->Count(); ++i){
        IWindow* wnd = this->GetByIndex(i);
        if (wnd && wnd->GetID() == wndID){
            Mgr<IWindow>::Remove(wnd);
        }
    }
}

IWindow* WindowMgr::GetByID(Uint32 wndID)
{
    if (wndID < 0) return 0;
    for (size_t i = 0; i < this->Count(); ++i){
        IWindow* wnd = this->GetByIndex(i);
        if (wnd && wnd->GetID() == wndID){
            return wnd;
        }
    }
    return 0;
}

void WindowMgr::RemoveByName(const char* name)
{
    if (!name) return;
    for (size_t i = 0; i < this->Count(); ++i){
        IWindow* wnd = this->GetByIndex(i);
        if (wnd && strcmp(wnd->GetName(), name) == 0){
            Mgr<IWindow>::Remove(wnd);
        }
    }
}

IWindow* WindowMgr::GetByName(const char* name)
{
    if (!name) return 0;
    for (size_t i = 0; i < this->Count(); ++i){
        IWindow* wnd = this->GetByIndex(i);
        if (wnd && strcmp(wnd->GetName(), name) == 0){
            return wnd;
        }
    }
    return 0;
}

EDUI_NAMESPACE_END